package com.example.wwk.graduationpractice.Adapter;


import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.wwk.graduationpractice.Activity.AnswerActivity;
import com.example.wwk.graduationpractice.Activity.ChatConsultActivity;
import com.example.wwk.graduationpractice.Bean.PsychologistBean;
import com.example.wwk.graduationpractice.Bean.QuestionBean;
import com.example.wwk.graduationpractice.R;

import java.util.List;

/**
 * Created by wwk on 2017/3/2.
 */

public class QuestionAdapter extends RecyclerView.Adapter<QuestionAdapter.ViewHolder> {

    private List<QuestionBean> questionBeanList;
    private Context mcontext;
    private String thisUser;
    private int identity;

    static class ViewHolder extends RecyclerView.ViewHolder {

        CardView cardView;
        TextView name;
        TextView time;
        TextView content;

        public ViewHolder(View itemView) {
            super(itemView);
            cardView = (CardView) itemView;
            name= (TextView)itemView.findViewById(R.id.quesion_item_name);
            time= (TextView)itemView.findViewById(R.id.quesion_item_time);
            content= (TextView)itemView.findViewById(R.id.quesion_item_content);

        }
    }

    public QuestionAdapter(List<QuestionBean> mList, String thisuser, int identity2) {

        questionBeanList = mList;
        thisUser = thisuser;
        identity = identity2;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(mcontext==null){
            mcontext = parent.getContext();
        }
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.question_item, parent, false);

        final ViewHolder holder = new ViewHolder(view);
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int position = holder.getAdapterPosition();
                QuestionBean questionBean = questionBeanList.get(position);
                Intent intent = new Intent(mcontext, AnswerActivity.class);
                intent.putExtra("questionBean",questionBean);
                intent.putExtra("thisuserName",thisUser);
                intent.putExtra("identity",identity);
                mcontext.startActivity(intent);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        QuestionBean questionBean = questionBeanList.get(position);
        holder.name.setText(questionBean.getName());
        holder.time.setText(questionBean.getTime());
        holder.content.setText(questionBean.getContent());
    }
    @Override
    public int getItemCount() {
        return questionBeanList.size();
    }

}
